//
//  SASoundPlayer.m
//  01_kakin
//
//  Created by jon due on 12/03/27.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SASoundPlayer.h"

#define fileType    @"mp3"

@implementation SASoundPlayer

@synthesize AVPlayer = _AVPlayer;
@synthesize delegate = _delegate;

-(void)dealloc{
    [ _AVPlayer release ],_AVPlayer = nil;
    [ super dealloc ];
}

-(id)init{
    
    self = [ super init ];
    if(self){
        //
        
    }
    return self;
}

-(void)play:(NSString*)fileName{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:fileType];
    NSURL *url = [NSURL fileURLWithPath:path];
    self.AVPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    self.AVPlayer.delegate = self;
    
    [self.AVPlayer play];
    
}

-(void)stop{
    
    [ self.AVPlayer stop ];
    
}

/* ============================================================================== */
#pragma mark - AVAudioPlayerDelegate
/* ============================================================================== */

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    
    [ self.delegate soundPlayer:player ];
    
}

@end
